package com.wc.alorithm_blue_bridge._字符串.KMP.Q3010;

import java.io.*;

/**
 * @Author congege
 * @Description
 * @Date Created in 2023/12/1-14:53
 */
public class Main2 {
    private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static PrintWriter out= new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(System.out)));
    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(reader.readLine());
        String s = reader.readLine();

        int[] next = new int[n + 1];
        next[0] = -1;
        next[1] = 0;
        int i = 2,k;
        int ans = 0;
        while (i <= n){
            k = next[i - 1];
            while (k != -1 && s.charAt(i - 1) != s.charAt(k)){
                k = next[k];
            }
            next[i] = k + 1;
            ans = Math.max(ans,next[i]);
            i++;
        }
        out.println(ans);
        out.flush();
    }
}
